package com.xiaojie.dubbo.server.loadBalance;

import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

/*
 *  随机算法
 * @todo
 * @author xiaojie
 * @date 2021/8/6 10:54
 * @return
 */
public class RandomBalance  implements LoadBalance<String>{
    @Override
    public String select(List<String> repos) {
        /*String value = repos.get(new Random().nextInt(repos.size()));
        System.out.println(value);
        return value;*/
        if (repos.size()<0){
            throw new RuntimeException(" service is null");
        }
        int index = ThreadLocalRandom.current().nextInt(repos.size());
        return repos.get(index);
    }
}
